package com.example.springbootthreaddemo.demo02;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @Author: jixiaotian.ch@qq.com
 * @Date : 2020/8/26
 */
public class Demo {

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while(true){
//                    TimeUnit.SECONDS.sleep(100);
                    LockSupport.parkUntil(100000);
            }
        },"STATUS_01").start();//阻塞 TIMED_WAITING

        new Thread(()->{
            while(true) {
                synchronized (Demo.class) {
                    try {
                        Demo.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"STATUS_02").start();//阻塞  WAITING

        new Thread(new BlockedDemo(),"BLOCKED-DEMO-01").start();
        new Thread(new BlockedDemo(),"BLOCKED-DEMO-02").start();
        //阻塞  BLOCKED 抢占锁
    }

    static class BlockedDemo extends Thread {
        @Override
        public void run() {
            synchronized (BlockedDemo.class) {
                while (true) {
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

}


